package com.s10.ecloud.web.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.s10.ecloud.web.dao.IUserDAO;
import com.s10.ecloud.web.dao.impl.UserDAO;
import com.s10.ecloud.web.model.EnterpriseUser;
import com.s10.ecloud.web.model.IndividualUser;
import com.s10.ecloud.web.model.SystemUser;
import com.s10.ecloud.web.model.User;
import com.s10.ecloud.web.service.ILoginService;
import com.s10.ecloud.web.util.MD5;

@Service
public class LoginService implements ILoginService {

	@Resource
	private IUserDAO<User> userDao = null;

	@Override
	public String userLogin(SystemUser user) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int userRegister(SystemUser user, IndividualUser userinfo, int depid) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public SystemUser findUserbyUsername(String username) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public IndividualUser findUserinfo(SystemUser user) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void modifyUserinfo(String name, String gender, String email,
			String pid, String phone, SystemUser user) {
		// TODO Auto-generated method stub

	}

	@Override
	public void modifyUserRights(String username, String right) {
		// TODO Auto-generated method stub

	}

	@Override
	public String modifyUserPwd(int userId, String password) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List findAllUser() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List findAllUserByDep(SystemUser user) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List findAllUserByRight(String right) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void recoverUserstateByUsername(String username) {
		// TODO Auto-generated method stub

	}

	@Override
	public void freezeUserstateByUsername(String username) {
		// TODO Auto-generated method stub

	}

	@Override
	// 登录界面邮箱、密码是否正确的验证
	public User getUserByMail(String mail, String pwd) {
		User user = null;
		List<User> userList;

		// 系统用户的时候
		userList = userDao.findIndUserByEMail(mail);

		if (userList == null || userList.size() == 0) {

			userList = userDao.findSysUserByEMail(mail);
			if (userList == null || userList.size() == 0) {

				userList = userDao.findEntUserByEMail(mail);
			}
		}

		if (userList != null && userList.size() > 0) {
			if (MD5.MD5Encode(pwd).equals(userList.get(0).getPassword())) {
				user = userList.get(0);
			}
		}
		return user;
	}
}
